package com.gc.business.service.impl;

import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gc.common.utils.StringUtils;
import org.springframework.stereotype.Service;
import com.gc.business.mapper.VerificationCodeMapper;
import com.gc.business.domain.VerificationCode;
import com.gc.business.service.IVerificationCodeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;

/**
 * 手机验证码 服务层实现
 * 
 * @author hruiyan
 * @date 2020-11-23
 */
@Slf4j
@Service
public class VerificationCodeServiceImpl extends ServiceImpl<VerificationCodeMapper, VerificationCode> implements IVerificationCodeService {

    @Override
    public List<VerificationCode> list(VerificationCode verificationCode){
        LambdaQueryWrapper<VerificationCode> wrapper = new LambdaQueryWrapper<>();
        if(verificationCode != null){
            if(StringUtils.isNotEmpty(verificationCode.getId())){
                wrapper.eq(VerificationCode::getId, verificationCode.getId());
            }
            if(StringUtils.isNotEmpty(verificationCode.getPhoneNum())){
                wrapper.eq(VerificationCode::getPhoneNum, verificationCode.getPhoneNum());
            }
            if(StringUtils.isNotEmpty(verificationCode.getPhoneCode())){
                wrapper.eq(VerificationCode::getPhoneCode, verificationCode.getPhoneCode());
            }
            if(StringUtils.isNotEmpty(verificationCode.getDeadTime())){
                wrapper.eq(VerificationCode::getDeadTime, verificationCode.getDeadTime());
            }
            if(StringUtils.isNotEmpty(verificationCode.getCreateTime())){
                wrapper.eq(VerificationCode::getCreateTime, verificationCode.getCreateTime());
            }
            if(StringUtils.isNotEmpty(verificationCode.getUpdateTime())){
                wrapper.eq(VerificationCode::getUpdateTime, verificationCode.getUpdateTime());
            }
        }
        return baseMapper.selectList(wrapper);
    }

    @Override
    public VerificationCode selectCodeByNew(String phoneNum){
        return baseMapper.selectCodeByNew(phoneNum);
    }
}
